#include <iostream>
using namespace std;

// 3换一，可借一满三后换一，可以换多少次
int get(int n)
{
    if (n < 2)
        return 0;
    int sum = 0;
    while (n > 2)
    {
        int left = n % 3;
        int get1 = n / 3;
        sum += get1;
        n = n / 3 + left;
    }
    if (n == 2) {
        sum++;
    }
    return sum;
}

int main () {
    int n;
    while(1) {
        cin >> n;
        if (n == 0) {
            break;
        }
        cout << get(n) << endl;
    }
    return 0;
}